from fastapi import APIRouter
from pydantic import BaseModel
from finance.python.services import forgot_password_services

forgot_password_route = APIRouter(
    prefix="/api",
    tags=["forgot_password"]
)


class VerifyRequest(BaseModel):
    phone: str
    verifyCode: str


@forgot_password_route.post(path="/verify", summary="验证手机号及其验证码")
async def verify(verify_data: VerifyRequest):
    """
    验证手机号及其验证码
    :param verify_data: 验证请求数据
    :return: 验证结果
    """
    return await forgot_password_services.verify(
        verify_data.phone,
        verify_data.verifyCode
    )


class ResetPasswordRequest(BaseModel):
    phone: str
    password: str


@forgot_password_route.post(path="/reset-password", summary="根据手机修改密码")
async def reset_password(reset_password_data: ResetPasswordRequest):
    """
    根据手机修改密码
    :param reset_password_data: 重置密码请求数据
    :return: 重置密码结果
    """
    return await forgot_password_services.reset_password(
        reset_password_data.phone,
        reset_password_data.password
    )
